import os

# for root, dirs, files in os.walk('./'):
#     print('root: ', root)
#     print('dirs: ', dirs)
#     print('files: ', files)


def search_file(path, search_text):
    """
    查询指定目录下的包含search_text的文件

    :param path: 路径
    :param search_text: 所包含的字符串
    :return: 带有路径的list
    """
    result_list = []
    file_names = [os.path.join(root, fn) for root, dirs, files in os.walk(path) for fn in files]
    for fn in file_names:
        file_name = os.path.split(fn)[1]
        if search_text in file_name:
            result_list.append(fn)
    return result_list


# 编写一个程序，能在当前目录以及当前目录的所有子目录下查找文件名包含指定字符串的文件，并打印出相对路径
# print(search_file(os.getcwd(), '.py'))
print(search_file('.', '.py'))
